import java.util.*;

// 49. 字母异位词分组
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> hash = new HashMap<>();
        // 1. 异位词分组并排序
        for (String s : strs) {
            char[] ch = s.toCharArray();
            Arrays.sort(ch);
            String key = new String(ch);

            if (!hash.containsKey(key)) {
                hash.put(key, new ArrayList());
            }
            hash.get(key).add(s);
        }
        // 2. 获取值
        return new ArrayList(hash.values());
    }
}